import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/8 15:19
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    public String[] getFolderNames(String[] names) {
        int n = names.length;
        String[] ans = new String[n];
        // 字符串出现的次数
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String name = names[i];
            if (map.containsKey(name)) {
                // 如果集合中出现当前字符串
                for (int k = map.get(name) + 1; ; k++) {
                    String newName = name + "(" + k  + ")";
                    if (!map.containsKey(newName)) {
                        ans[i] = newName;
                        map.put(name, k);
                        // 将新的字符串加入集合
                        map.put(newName, 0);
                        break;
                    }
                }
            }else {
                ans[i] = name;
                map.put(name, 0);
            }
        }
        return ans;
    }
}
